/**
 * Created by jack on 2017/12/14.
 */
'use strict';

goog.provide('Blockly.JavaScript.control');

goog.require('Blockly.JavaScript');


Blockly.JavaScript.control_wait = function() {
    //wait time
  var delay_time = Blockly.JavaScript.valueToCode(this, 'DURATION', Blockly.JavaScript.ORDER_ATOMIC) || '1';

  var code = 'ActionBlock.wait('+delay_time*1000+');\n';
  return code;

};

Blockly.JavaScript.operator_lt = function() {
  var argument0 = Blockly.JavaScript.valueToCode(this, 'OPERAND1',Blockly.JavaScript.ORDER_ATOMIC) || '0';
  var argument1 = Blockly.JavaScript.valueToCode(this, 'OPERAND2',Blockly.JavaScript.ORDER_ATOMIC) || '1';
  var code = argument0+'<'+argument1;
  return [code,Blockly.JavaScript.ORDER_NONE];
};

Blockly.JavaScript.operator_equals = function() {
  var argument0 = Blockly.JavaScript.valueToCode(this, 'OPERAND1',Blockly.JavaScript.ORDER_ATOMIC) || '0';
  var argument1 = Blockly.JavaScript.valueToCode(this, 'OPERAND2',Blockly.JavaScript.ORDER_ATOMIC) || '1';
  var code = argument0+'=='+argument1;
  return [code,Blockly.JavaScript.ORDER_NONE];
};

Blockly.JavaScript.operator_gt = function() {
  var argument0 = Blockly.JavaScript.valueToCode(this, 'OPERAND1',Blockly.JavaScript.ORDER_ATOMIC) || '0';
  var argument1 = Blockly.JavaScript.valueToCode(this, 'OPERAND2',Blockly.JavaScript.ORDER_ATOMIC) || '1';
  var code = argument0+'>'+argument1;
  return [code,Blockly.JavaScript.ORDER_NONE];
};

Blockly.JavaScript.operator_and = function() {
  var argument0 = Blockly.JavaScript.valueToCode(this, 'OPERAND1',Blockly.JavaScript.ORDER_ATOMIC) || 'flase';
  var argument1 = Blockly.JavaScript.valueToCode(this, 'OPERAND2',Blockly.JavaScript.ORDER_ATOMIC) || 'flase';
  var code = argument0+' && '+argument1;
  return [code,Blockly.JavaScript.ORDER_NONE];
};

Blockly.JavaScript.operator_or = function() {
  var argument0 = Blockly.JavaScript.valueToCode(this, 'OPERAND1',Blockly.JavaScript.ORDER_ATOMIC) || 'flase';
  var argument1 = Blockly.JavaScript.valueToCode(this, 'OPERAND2',Blockly.JavaScript.ORDER_ATOMIC) || 'flase';
  var code = argument0+' || '+argument1;
  return [code,Blockly.JavaScript.ORDER_NONE];
};

Blockly.JavaScript.operator_not = function() {
  var argument0 = Blockly.JavaScript.valueToCode(this, 'OPERAND',Blockly.JavaScript.ORDER_ATOMIC) || 'flase';
  var code = '! '+argument0;
  return [code,Blockly.JavaScript.ORDER_NONE];
};
